// appfront/src/api/index.js
import Vue from 'vue'
//vue原型链上绑定  
import Axios from 'axios'
// Vue.prototype.$http = axios;

//创建axios实例对象
const axiosInstance = Axios.create({
    baseURL: '/apilog',
    timeout: 5000,
    withCredentials: true//允许携带cookie,发送post请求会自动带上cookie
    //0325+
})
axiosInstance.defaults.headers.post['Content-Type'] = 'multipart/form-data';
    
//请求拦截器
// 通过拦截器处理csrf问题，这里的正则和匹配下标可能需要根据实际情况小改动
axiosInstance.interceptors.request.use((config) => {
    //const regex = /.*csrftoken=([^;.]*).*$/
    //config.headers['X-CSRFToken'] = document.cookie.match(regex) === null ? null : document.cookie.match(regex)[1]

    config.headers['Content-Type']='application/json'
    return config
})


//响应拦截器
axiosInstance.interceptors.response.use(
    response => {
        return response
    },
    error => {
        return Promise.reject(error)
    }
)

//vue项目中引入axios
Vue.prototype.axios = axiosInstance

// axiosInstance.get('http://www.liulongbin.top:3006/api/getbooks/:id',(res,req) =>{
//     res.send(req.params.id)
// })

//对axios进行封装
export default axiosInstance